package ptij.verifier.test;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.*;
import ptolemy.data.type.*;

public class recur extends TypedAtomicActor {

   public recur(CompositeEntity container, String Name) throws
           NameDuplicationException, IllegalActionException  {
       super(container, Name);      

       plus = new TypedIOPort(this, "plus", true, false);
       output = new TypedIOPort(this, "output", false, true);
   }

   public TypedIOPort plus;
   public TypedIOPort output;


   public void fire() throws IllegalActionException {

       IntToken it = (IntToken) plus.get(0);
       
       int fac = fac(it.intValue());
       
       output.broadcast(new IntToken(fac));
   
   }
   
    private int fac(int v) {
        if(v == 1) 
	    return 1;
	else
	   return v * fac(v - 1);
    
    }

   
}
